﻿using Couchbase;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GuoZhiQi.MiddleCache.Object.Atomic
{
    public abstract class CouchBaseAtomic<T> : CouchBaseObject
    {
        #region Main value.

        /// <summary>
        /// Value of this parameter.
        /// </summary>
        public abstract T Value
        {
            get;
            set;
        }

        #endregion Main value.

        #region Constructor

        /// <summary>
        /// Constructor of this object.
        /// </summary>
        /// <param name="client">Membase client to work with.</param>
        public CouchBaseAtomic(CouchbaseClient client)
            : base(client)
        {
            this.JsonInSync = true;

            this._client = client;

            if (this._client == null)
                throw new ArgumentNullException("Client");
        }

        /// <summary>
        /// Constructor of this object.
        /// </summary>
        /// <param name="client">Membase client to work with.</param>
        /// <param name="objectKey">String key of the object.</param>
        /// <param name="TryLoadFromDB">True if object should be instantly loaded from Membase.</param>
        public CouchBaseAtomic(CouchbaseClient client, string objectKey, bool TryLoadFromDB = false)
            : base(client)
        {
            this.Key = objectKey;
            this._client = client;

            if (this._client == null)
                throw new ArgumentNullException("Client");

            if (TryLoadFromDB)
                this.Refresh();
        }

        #endregion Constructor
    }
}
